package com.zj.fx.controller.info;

import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.model.custom.Tablepar;
import com.github.pagehelper.PageInfo;
import com.zj.fx.model.info.InfoFile;
import com.zj.fx.model.info.InfoFileExample;
import com.zj.fx.model.info.InfoNecessary;
import com.zj.fx.service.info.InfoFileService;
import com.zj.fx.service.info.InfoNecessaryService;
import com.zj.fx.util.SnowflakeIdWorker;
import com.zj.fx.util.UploadFileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Example;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;

/**
 * 必备条件指标库表Controller
 * @ClassName: InfoNecessaryController
 * @author fuce
 * @date 2023-06-06 14:27:19
 */
@Api(value = "必备条件指标库表")
@Controller
@RequestMapping("/InfoNecessaryController")
public class InfoNecessaryController extends BaseController {

    private String prefix = "info/infoNecessary";

    @Autowired
    private InfoNecessaryService infoNecessaryService;

    @Autowired
    private UploadFileUtil fileUtil;

    @Autowired
    private InfoFileService infoFileService;

    /**
     * 必备条件指标库表页面展示
     * @param model
     * @return String
     * @author fuce
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:infoNecessary:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "必备条件指标库表", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:infoNecessary:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, InfoNecessary infoNecessary) {
        PageInfo<InfoNecessary> page = infoNecessaryService.list(tablepar,infoNecessary);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     * @param 
     * @return
     */
    //@Log(title = "必备条件指标库表新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:infoNecessary:add")
    @ResponseBody
    public AjaxResult add(@RequestBody InfoNecessary infoNecessary) {
        int b = infoNecessaryService.insertSelective(infoNecessary);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 必备条件指标库表删除
     * @param ids
     * @return
     */
    //@Log(title = "必备条件指标库表删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:infoNecessary:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = infoNecessaryService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("InfoNecessary", infoNecessaryService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "必备条件指标库表修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:infoNecessary:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InfoNecessary infoNecessary) {
        return toAjax(infoNecessaryService.updateByPrimaryKeySelective(infoNecessary));
    }

}
